package com.example.service.impl;

import com.example.dto.ReportDTO;
import com.example.mapper.ReportMapper;
import com.example.result.CommonResult;
import com.example.service.ReportService;
import com.example.vo.ReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject："smart-property"
 * @BelongsPackage："com.example.service.impl"
 * @CreateTime："2022-11-15 13:44"
 * @Description：举报
 * @Author：LK
 */
@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    /**
     * @description:举报全查
     * @author: lk
     * @date: 2022/11/15 19:52
     * @param: reportVO
     * @return: java.util.List<com.example.dto.ReportDTO>
     **/
    @Override
    public CommonResult reportCheck(ReportVO reportVO) {
        // 计算每页数据的开始
        reportVO.setPageNum((reportVO.getPageNum() - 1) * reportVO.getPageSize());
        Map<String, Object> map = new HashMap<>();
        try{
            // 查询举报数据
            List<ReportDTO> reportDTOS = reportMapper.reportCheck(reportVO);
            // 查询数据总数
            Integer total = reportMapper.reportCheckTotal(reportVO);
            map.put("msg",reportDTOS);
            map.put("total",total);
            return CommonResult.ok(map);
        }catch (Exception e){
            return CommonResult.fail();
        }
    }

    /**
     * @description:举报审核-不通过
     * @author: lk
     * @date: 2022/11/15 19:50
     * @param: reportNumber
     * @return: java.lang.Integer
     **/
    @Override
    public CommonResult examineReport(String reportNumber) {
        try{
            reportMapper.examineReport(reportNumber);
            return CommonResult.ok();
        }catch (Exception e){
            return CommonResult.fail();
        }
    }

    /**
     * @description:举报审核-通过
     * @author: lk
     * @date: 2022/11/15 19:50
     * @param: reportNumber
     * @return: java.lang.Integer
     **/
    @Override
    public CommonResult examineReport2(String reportNumber) {
        try{
            reportMapper.examineReport2(reportNumber);
            return CommonResult.ok();
        }catch (Exception e){
            return CommonResult.fail();
        }
    }

    /**
     * @description:删除举报
     * @author: lk
     * @date: 2022/11/15 21:28
     * @param: reportNumber
     * @return: java.lang.Integer
     **/
    @Override
    public CommonResult deleteReport(String reportNumber) {
        try{
            reportMapper.deleteReport(reportNumber);
            return CommonResult.ok();
        }catch (Exception e){
            return CommonResult.fail();
        }
    }
}
